package com.noahplat.person.mapper;

import com.noahplat.person.pojo.PersonInfo;
import com.noahplat.person.utils.PersonHealthDao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @InterfaceName: PersonInfoMapper
 * @Description: 人员详细资料mapper
 * @Author 李景星
 * @Date 2021/3/8
 * @Version 1.0
 */
public interface PersonInfoMapper extends Mapper<PersonInfo> {
    //根据账套id查询人员信息
    @Select("select i.id,i.pid,i.name,i.card,i.address,i.phone,i.qqno,i.wxno,i.email,i.cname,i.cphone,i.caddress,i.cqqno," +
            "i.wxno,i.cemail,p.no as no,p.id as personid,p.acctid as acctid,p.userid as userid from tb_person_info i right join tb_person p on i.pid = p.id where  p.del = 'n' and p.acctid = #{acctid}")
    List<PersonInfo> getPensonInfoByAcctid(@Param("acctid") Long acctid);

    //根据名字模糊查询账套内的人员信息
    @Select("select i.id,i.pid,i.name,i.card,i.address,i.phone,i.qqno,i.wxno,i.email,i.cname,i.cphone,i.caddress,i.cqqno," +
            "i.wxno,i.cemail,p.no as no,p.id as personid,p.acctid as acctid,p.userid as userid from tb_person_info i right join tb_person p on i.pid = p.id where  p.del = 'n' and p.acctid = #{acctid} and i.name like concat(#{name},'%')")
    List<PersonInfo> getPensonInfoByName(@Param("acctid") Long acctid,@Param("name") String name);

    @Select("select i.name as name,p.no as no,d.imei as imei,d.default_flag as flag from tb_person_info i RIGHT JOIN tb_person p on i.pid = p.id LEFT JOIN tb_person_device d " +
            "on d.pid = p.id where p.del = 'n' and p.acctid = #{acctid}")
    List<PersonHealthDao> getHealth(@Param("acctid") Long acctid);
    @Select("select i.name as name,p.no as no,d.imei as imei,d.default_flag as flag from tb_person_info i,tb_person p,tb_person_device d where i.pid = p.id " +
            "and d.pid = p.id and p.del = 'n' and p.acctid = #{acctid} and i.name like concat(#{name},'%') ")
    List<PersonHealthDao> getHealthByName(@Param("acctid") Long acctid, @Param("name") String name);
}
